package net.oschina.renyong.query.generator.po;

import com.baomidou.mybatisplus.generator.config.rules.DbColumnType;

/**
 * 一个字段的内容信息
 * @author Timothy
 */
public class ContentField {

	/** 字段别名，要求必填 */
	private String aliasName;
	/** 字段在表中的列名，如siteId */
	private String columnName;
	/** 字段的全名，如a.siteId，有可能值为null */
	private String columnFullName;
	/** 字段对应的属性名称 */
	private String propertyName;
	/** java数据类型 */
	private DbColumnType columnType;
	/** 是否是select字段 */
	private boolean isSelect;
	/** 字段归属的表名 */
	private String tableName;

	public String getAliasName() {
		return aliasName;
	}

	public void setAliasName(String aliasName) {
		this.aliasName = aliasName;
	}

	public String getColumnName() {
		return columnName;
	}

	public ContentField setColumnName(String columnName) {
		this.columnName = columnName;
		return this;
	}

	public String getColumnFullName() {
		return columnFullName;
	}

	public ContentField setColumnFullName(String columnFullName) {
		this.columnFullName = columnFullName;
		return this;
	}

	public String getPropertyName() {
		return propertyName;
	}

	public ContentField setPropertyName(String propertyName) {
		this.propertyName = propertyName;
		return this;
	}

	public DbColumnType getColumnType() {
		return columnType;
	}

	public ContentField setColumnType(DbColumnType columnType) {
		this.columnType = columnType;
		return this;
	}

	public String getPropertyType() {
		if (null != columnType) {
			return columnType.getType();
		}
		return null;
	}

	public boolean isSelect() {
		return isSelect;
	}

	public ContentField setSelect(boolean select) {
		isSelect = select;
		return this;
	}

	public String getTableName() {
		return tableName;
	}

	public ContentField setTableName(String tableName) {
		this.tableName = tableName;
		return this;
	}

	/** 返回格式： 表名,字段名 */
	public String getTblColumn() {
		return tableName + "," + columnName;
	}

	/**
	 * 按JavaBean规则来生成get和set方法
	 */
	public String getCapitalName() {
		if (propertyName.length() <= 1) {
			return propertyName.toUpperCase();
		}
		// 第一个字母 小写、 第二个字母 大写 ，特殊处理
		String firstChar = propertyName.substring(0, 1);
		if (Character.isLowerCase(firstChar.toCharArray()[0])
				&& Character.isUpperCase(propertyName.substring(1, 2).toCharArray()[0])) {
			return firstChar.toLowerCase() + propertyName.substring(1);
		}
		return firstChar.toUpperCase() + propertyName.substring(1);
	}

}
